//------------------------------------------------------------------------------ 
//  <copyright file="ManagedExtractPlanarPose.h" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//  </copyright>
//------------------------------------------------------------------------------
#pragma once

// We have to ignore warning 4005 till MSRA updates to DX11. This is a known issue with Windows 8 SDK.

#include "EstimatePlanarPose.h"
#include "../ImageFrame.h"

namespace Microsoft {
    namespace Robotics {
        namespace Vision {
            namespace GroundTruthExtraction {
                using System::IDisposable;

                /// <summary>
                /// Managed interface to the MSR Planar Pose Estimator.
                /// This class is responsible for interfacing with native MSR Planar Pose Estimator
                /// to expose the funcationality of estimating the translation and rotation of the checkerboard
                /// with respect to the camera with given intrinsic and distortion parameters.
                /// </summary>
                public ref class ManagedPlanarPoseEstimator : public IDisposable
                {

                public:
                    /// <summary>
                    /// Initializes a new instance of the MSRPlanarPoseEstimator class.
                    /// </summary>
                    /// <param name="pdlColorIntrinsicParams">Camera intrinsic parameters </param>
                    /// <param name="cbColorIntrinsicParams">Camera intrinsic parameters length, should be 5</param>
                    /// <param name="pdlColorRDistortionParams">Camera distortion parameters </param>
                    /// <param name="cbColorIntrinsicParams">Camera distortion parameters length, should be 5</param>
                    ManagedPlanarPoseEstimator(
                        double* pdlColorIntrinsicParams,
                        int cbColorIntrinsicParams,
                        double* pdlColorRDistortionParams,
                        int cbColorRDistortionParams);

                    /// <summary>
                    /// Destroys an instance of the ManagedPlanarPoseEstimator class.
                    /// </summary>
                    ~ManagedPlanarPoseEstimator();
                    /// <summary>

                    /// <summary>
                    /// Disposes an instance of the ManagedPlanarPoseEstimator class.
                    /// </summary>
                    !ManagedPlanarPoseEstimator();

                    /// <summary>
                    /// Estimate planar translation and rotation for the given image
                    /// Rotation is output as (Euler) angles.
                    /// </summary>
					/// <param name="image">The image in Gray 8 format </param>
                    /// <param name="pdlTranslation">The translation in x, y, z directions of the planar checker board in mm</param>
                    /// <param name="cbTranslation">The length of translation buffer, should be 3</param>
                    /// <param name="pdlRotation">The rotation in x, y, z directions of the planar checker board in radians</param>
                    /// <param name="cbRotation">The length of rotation array, should be 3</param>
                    bool EstimatePose(
						ImageFrameGray8^ image,
                        double* pdlTranslation,
                        DWORD cbTranslation,
                        double* pdlRotation,
                        DWORD cbRotation);

                    /// <summary>
                    /// Estimate planar translation and rotation for the given image
                    /// Rotation is output as a unit quaternion.
                    /// </summary>
					/// <param name="image">The image in Gray 8 format </param>
                    /// <param name="pdlTranslation">The translation in x, y, z directions of the planar checker board in mm</param>
                    /// <param name="cbTranslation">The length of translation buffer, should be 3</param>
                    /// <param name="pdlQuaternion">The rotation of the planar checker board, specified as a unit quaternion</param>
                    /// <param name="cbQuaternion">The length of rotation array, should be 4</param>
                    bool EstimatePoseWithRotationAsUnitQuaternion(
						ImageFrameGray8^ image,
                        double* pdlTranslation,
                        DWORD cbTranslation,
                        double* pdlQuaternion,
                        DWORD cbQuaternion);

                    
                private:                    

                    ///  <summary> Reference to the native planar pose estimator interface. </summary>
                    MSRPlanarPoseEstimator* m_planarPoseEstimator;

                    ///  <summary> Track whether Dispose has been called. </summary>
                    bool m_fDisposed;
                };            
}}}}
